%% initialisation values %%


N = 256;
f = 330.5;
f_sample = 1024;
amplitude = 5.0;
Ts = 1 /f_sample;
T = 1/f;


%% Sampling %%


f1 = [-N/2:((N/2)-1)]*(f_sample/N);
t = [0:(N-1)]*Ts;

x = zeros(1,N+1);
x = amplitude * sin(2 * pi * f * t);


%% FFT computing %%


X = fft(x)
Magnitude_X = abs(X);


%% zero padding init %%


M = 2048;
t2 = [0:(M/2)-1]*Ts;
f2 = [-M/2:(M/2)-1]*(f_sample/M);

gn = zeros(1,M);


%% zero padding %%


for count = 1:M
    if count < N
        gn(count) = x(count);
    else
        gn(count) = 0;
    end
end

Gn = abs(fft(gn));


%% magnitude plot and zero padding plot %%


    pl(1) = plot(f1,fftshift(Magnitude_X),'*')
    xlabel('frequency (Hz)')
    ylabel('Magnitude')
hold on
    pl(2) = plot(f2,fftshift(Gn),'r')
    xlabel('frequency (Hz)')
    ylabel('Magnitude')
h1 = legend('eg1','eg2');    
    set(h1,'Location','NorthEast')
h2 = legend(pl,'fft of the Magnitude of X vs frequency','fft of the magnitude zero-padded X vs frequency');    
    set(h2,'Location','NorthEast')
hold off


% figure
% plot(f1,fftshift(Magnitude_X),'r')
%     xlabel('frequency')
%     ylabel('Magnitude')
% title('fft of the Magnitude of X vs frequency')
%     
%     figure
% plot(f2,fftshift(Gn),'b')
%     xlabel('frequency')
%     ylabel('Magnitude zero padded X')
% title('fft of the magnitude zero-padded X vs frequency')
